package kr.saeildamil.androidstudy_second31;

import java.util.ArrayList;

import kr.saeildamil.androidstudy_second.R;
import android.app.Activity;
import android.gesture.Gesture;
import android.gesture.GestureLibraries;
import android.gesture.GestureLibrary;
import android.gesture.GestureOverlayView;
import android.gesture.GestureOverlayView.OnGesturePerformedListener;
import android.gesture.Prediction;
import android.os.Bundle;
import android.widget.TextView;

public class CustomGesture extends Activity {
	TextView mTextCounter;
	int mCount=10;
	GestureLibrary mGesLib;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ch31_customgesture);
		
		mTextCounter=(TextView) findViewById(R.id.ch31_customgesture_count);
		mTextCounter.setText(Integer.toString(mCount));
		
		mGesLib=GestureLibraries.fromRawResource(this, R.raw.gestures);
		if(mGesLib.load()==false){
			finish();
		}
		GestureOverlayView gestures=(GestureOverlayView) findViewById(R.id.gestureOverlayView1);
		gestures.addOnGesturePerformedListener(mListener);
	}
	
	OnGesturePerformedListener mListener=new OnGesturePerformedListener() {
		
		@Override
		public void onGesturePerformed(GestureOverlayView overlay, Gesture gesture) {
			ArrayList<Prediction>predictions=mGesLib.recognize(gesture);
			
			if(predictions.size()!=0){
				Prediction prediction=predictions.get(0);
				String name=prediction.name;
				if(prediction.score>0.5){
					if(name.equals("kiyuk")){
						mCount++;
					}else if(name.equals("nieun")){
						mCount--;
					}else if(name.equals("digut")){
						mCount=10;
					}
					mTextCounter.setText(""+mCount);
					
				}
			}
		}
	};
}
